﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WinFormsApp1.Common;

namespace WinFormsApp1.SuYi.Week2WinForm
{
    public partial class DeductionWinForm : Form
    {
        public DeductionWinForm()
        {
            InitializeComponent();
        }

        private async void button1_Click(object sender, EventArgs e)
        {
           

        }

        private void uiComboDataGridView1_Click(object sender, EventArgs e)
        {

        }
        /// <summary>
        /// 扣减项新增按钮点击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>

        private async void uiButton1_Click(object sender, EventArgs e)
        {

            Deductions dc = new Deductions();
            dc.DeductionName = uiTextBox1Name.Text;
            dc.DeductionPrice = Convert.ToDecimal(uiTextBox2Price.Text);
            if(uiCheckBox1DeductionBusiness.Checked)
            {
                dc.DeductionBusiness = "活畜管理";
            }
            if (uiCheckBox2DeductionBusiness.Checked)
            {
                dc.DeductionBusiness = "屠宰管理";
            }

            dc.DeductionRemark = uiTextBox3DeductionRemark.Text;
            dc.DeductionStatu = false;
            dc.IsDel = 0;

            var list = await HttpClientHelper.RequestUrl<Deductions, ApiResult<Deductions>>(URLCommon.Url1, "/Week2Setup/AddDeductions", HttpClientHelper.MethodType.POST, dc);

            if (list.Code > 0)
            {
                MessageBox.Show("新增成功");
            }
            else
            {
                MessageBox.Show("新增成功");
                return;
            }
        }


        /// <summary>
        /// 扣减项设置字段
        /// </summary>
        public class Deductions
        {
            /// <summary>
            /// 扣减项编号
            /// </summary>
            [Key]
            public int DeductionId { get; set; }
            /// <summary>
            /// 扣减项名称
            /// </summary>
            public string DeductionName { get; set; }
            /// <summary>
            /// 扣减项金额
            /// </summary>
            public decimal DeductionPrice { get; set; }
            /// <summary>
            /// 项目所属业务
            /// </summary>
            public string DeductionBusiness { get; set; }
            /// <summary>
            /// 使用状态
            /// </summary>
            public bool DeductionStatu { get; set; }
            /// <summary>
            /// 备注
            /// </summary>
            public string DeductionRemark { get; set; }
            /// <summary>
            /// 逻辑删除
            /// </summary>
            public int IsDel { get; set; }
        }

    }
}
